package com.wayeal.word;

import com.alibaba.fastjson.JSONObject;
import com.wayeal.word.vo.TestVO;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chen.chao
 * @version 2021-08-16 9:00
 */
public class Test {

    public void test(){
        List<Map<String,Object>> listdata = new ArrayList<>();
        Map<String,Object> map1 = new HashMap<>();
        Map<String,Object> map2 = new HashMap<>();
        Map<String,Object> rest = new HashMap<>();
        List<TestVO> list = new ArrayList<>();
        for(int i = 0;i<10;i++){
            TestVO vo = new TestVO("2020/4/3","13:30","13:50",(6.5+i)+"","5.8","0");
            list.add(vo);
        }
        map1.put("date","2021/8/17");
        map1.put("list",list);
        map2.put("date","2021/8/18");
        map2.put("list",list);
        listdata.add(map1);
        listdata.add(map2);
        rest.put("data",listdata);
        String filePath = "F:/";
        //文件唯一名称
        String fileOnlyName = "new.doc";
        /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/
        WordUtil.createWord(rest, "testa.ftl", filePath, fileOnlyName);
    }

    public static void main(String[] args) {
        /** 用于组装word页面需要的数据 */
        Map<String, Object> dataMap = new HashMap<String, Object>();

        List<JSONObject> listinfo = new ArrayList<>();
//        List<Object> datas = new ArrayList<>();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("date","2019/4/23");
        jsonObject.put("beginDate","10:23");
        jsonObject.put("endDate","11:02");
        jsonObject.put("z0","0");
        jsonObject.put("zi","0.01");
        jsonObject.put("zd","-0.01");
        jsonObject.put("s0","82.85");
        jsonObject.put("si","-90.23");
        jsonObject.put("sd","-90.23");
        jsonObject.put("remark","-起始");
        listinfo.add(jsonObject);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("date","2019/4/24");
        jsonObject2.put("beginDate","10:23");
        jsonObject2.put("endDate","11:02");
        jsonObject2.put("z0","0");
        jsonObject2.put("zi","0.01");
        jsonObject2.put("zd","-0.01");
        jsonObject2.put("s0","82.85");
        jsonObject2.put("si","-90.23");
        jsonObject2.put("sd","-90.23");
        jsonObject2.put("remark","校验");
        listinfo.add(jsonObject2);

        dataMap.put("listinfo",listinfo);
        dataMap.put("tester","小白");
        dataMap.put("factory","皖仪科技");
        dataMap.put("testPlace","兴寿实验室");
        dataMap.put("max","-0.03");
        dataMap.put("main","-0.43");
        String filePath = "F:/";
        //文件唯一名称
        String fileOnlyName = "生成Word文档2.doc";
        /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/
        WordUtil.createWord(dataMap, "cems.ftl", filePath, fileOnlyName);
    }
}
